package vip.youngboy.freejump.command;

import org.activiti.engine.impl.cmd.NeedsActiveTaskCmd;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.IdentityLinkEntityManager;
import org.activiti.engine.impl.persistence.entity.TaskEntity;

import java.util.Set;

public class ReportActionCommand extends NeedsActiveTaskCmd {

    private Set<String> candidateUsers;

    public ReportActionCommand(String taskId, Set<String> candidateUsers) {
        super(taskId);
        this.candidateUsers = candidateUsers;
    }

    @Override
    protected Object execute(CommandContext commandContext, TaskEntity task) {
        //清空当前任务的候选人和执行人
        IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager();
        //清除候选人
        identityLinkEntityManager.deleteIdentityLinksByTaskId(taskId);
        //设置assignee为空
        commandContext.getTaskEntityManager().changeTaskAssignee(task, null);
        return null;
    }
}
